package com.tronsis.distribution.activity.login;

import android.os.Bundle;
import android.widget.TextView;

import com.tronsis.distribution.R;
import com.tronsis.distribution.bean.RulesMapBean;
import com.tronsis.distribution.biz.factory.CommonFactory;
import com.tronsis.distribution.util.CommonUtil;
import com.tronsis.library.activity.ToolBarBaseActivity;
import com.tronsis.library.db.DBUtil;
import com.tronsis.library.http.UICallBack;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AgreementActivity extends ToolBarBaseActivity {

    @BindView(R.id.tv_rule)
    TextView mTvRule;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_agreement);
        ButterKnife.bind(this);
        setTitle(true, "用户协议");
        RulesMapBean rulesMapBean = CommonUtil.getRulesMap(this);
        if (rulesMapBean != null && rulesMapBean.getRULE_USER() != null) {
            mTvRule.setText(rulesMapBean.getRULE_USER());
        }else {
            httpRulesMap();
        }

    }

    private void httpRulesMap() {
        try {
            CommonFactory.createBiz().getRulesMap(this, new UICallBack() {
                @Override
                public void onStart() {
                    showLoadingDialog();
                }

                @Override
                public void onRefresh(Object data) {
                    RulesMapBean bean = (RulesMapBean) data;
                    bean.setId(1);
                    DBUtil.getInstance(mContext).save(bean);
                    mTvRule.setText(bean.getRULE_USER());
                    dismissLoadingDialog();
                }

                @Override
                public void onFailure(int status) {
                    dismissLoadingDialog();

                }
            });
        } catch (Exception e) {
            e.printStackTrace();
            dismissLoadingDialog();
        }
    }
}
